package com.yc.config;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: shopping147_cloud
 * @description: feign文件上传配置
 * @author: zy
 * @create: 2025-07-24 15:44
 */
@Configuration
public class FeignMultipartSupportConfig {

    // Required for Feign to work with HttpMessageConverters (like for JSON)
    private final ObjectFactory<HttpMessageConverters> messageConverters;

    public FeignMultipartSupportConfig(ObjectFactory<HttpMessageConverters> messageConverters) {
        this.messageConverters = messageConverters;
    }

    @Bean
    public Encoder feignFormEncoder() {
        // This combines Spring's encoders with the FormEncoder to handle multipart requests
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }
}